<?php
declare(strict_types=1);

namespace app\model;

use think\Model;

class CouponOrder extends Model
{
    protected $autoWriteTimestamp = true;

    // 业务类型常量
    const TYPE_EXPRESS = 1; // 快递
    const TYPE_DIDI = 2; // 滴滴打车
    const TYPE_HUAXIAOZHU = 3; // 花小猪
    const TYPE_MEITUAN = 4; // 美团
    const TYPE_ELEME = 5; // 饿了么
    const TYPE_TAOBAO = 6; // 淘宝
    const TYPE_JD = 7; // 京东
    const TYPE_PDD = 8; // 拼多多
    const TYPE_DOUYIN = 9; // 抖音

    // 订单状态常量
    const STATUS_UNPAID = 0; // 未支付
    const STATUS_PAID = 1; // 已支付
    const STATUS_CANCELLED = 2; // 已取消

    // 关联用户
    public function user()
    {
        return $this->belongsTo(User::class);
    }

    // 关联商家
    public function merchant()
    {
        return $this->belongsTo(Merchant::class);
    }

    // 获取业务类型文字
    public function getBusinessTypeTextAttr()
    {
        $types = [
            self::TYPE_EXPRESS => '快递',
            self::TYPE_DIDI => '滴滴打车',
            self::TYPE_HUAXIAOZHU => '花小猪',
            self::TYPE_MEITUAN => '美团',
            self::TYPE_ELEME => '饿了么',
            self::TYPE_TAOBAO => '淘宝',
            self::TYPE_JD => '京东',
            self::TYPE_PDD => '拼多多',
            self::TYPE_DOUYIN => '抖音'
        ];
        return $types[$this->business_type] ?? '未知';
    }
} 